[XEND] Remove mistake of not checking xenstore's name entry for Dom0
authorAlastair Tse <atse@xensource.com>
Thu, 19 Oct 2006 16:48:54 +0000 (17:48 +0100)
committerAlastair Tse <atse@xensource.com>
Thu, 19 Oct 2006 16:48:54 +0000 (17:48 +0100)
Also fix logic with detecting whether devid is an int or not because
xm passes this as a string all the time.

Signed-off-by: Alastair Tse <atse@xensource.com>
tools/python/xen/xend/XendDomain.py
tools/python/xen/xend/XendDomainInfo.py

index 361c7613c56f53213ad2bcba50294f32cdf169e8..c6aa9645f1293f8cee88b57dfcb3ac35fc2a3594 100644 (file)
@@ -93,9 +93,8 @@ class XendDomain:
                 dom0info = [d for d in self._running_domains() \
                             if d['domid'] == DOM0_ID][0]
                 
+                dom0info['name'] = DOM0_NAME
                 dom0 = XendDomainInfo.recreate(dom0info, True)
-                # Sometimes this is not set?
-                dom0.setName(DOM0_NAME)
                 self._add_domain(dom0)
             except IndexError:
                 raise XendError('Unable to find Domain 0')
index 40d54285c5184014055116940cf9a48fcc3350d3..af774cf3039841516367022bb5a69bcbf53ef532 100644 (file)
@@ -29,6 +29,7 @@ import time
 import threading
 import re
 import copy
+from types import StringTypes
 
 import xen.lowlevel.xc
 from xen.util import asserts
@@ -183,7 +184,8 @@ def recreate(info, priv):
         raise XendError('No domain path in store for existing '
                         'domain %d' % domid)
 
-    log.info("Recreating domain %d, UUID %s.", domid, xeninfo['uuid'])
+    log.info("Recreating domain %d, UUID %s. at %s" %
+             (domid, xeninfo['uuid'], dompath))
 
     # need to verify the path and uuid if not Domain-0
     # if the required uuid and vm aren't set, then that means
@@ -193,29 +195,28 @@ def recreate(info, priv):
     #       abort or ignore, but there may be cases where xenstore's
     #       entry disappears (eg. xenstore-rm /)
     #
-    if domid != 0:
-        try:
-            vmpath = xstransact.Read(dompath, "vm")
-            if not vmpath:
-                log.warn('/dom/%d/vm is missing. recreate is confused, '
-                         'trying our best to recover' % domid)
-                needs_reinitialising = True
-                raise XendError('reinit')
-            
-            uuid2_str = xstransact.Read(vmpath, "uuid")
-            if not uuid2_str:
-                log.warn('%s/uuid/ is missing. recreate is confused, '
-                         'trying our best to recover' % vmpath)
-                needs_reinitialising = True
-                raise XendError('reinit')
-
-            uuid2 = uuid.fromString(uuid2_str)
-            if uuid1 != uuid2:
-                log.warn('UUID in /vm does not match the UUID in /dom/%d.'
-                         'Trying out best to recover' % domid)
-                needs_reinitialising = True
-        except XendError:
-            pass # our best shot at 'goto' in python :)
+    try:
+        vmpath = xstransact.Read(dompath, "vm")
+        if not vmpath:
+            log.warn('/local/domain/%d/vm is missing. recreate is '
+                     'confused, trying our best to recover' % domid)
+            needs_reinitialising = True
+            raise XendError('reinit')
+        
+        uuid2_str = xstransact.Read(vmpath, "uuid")
+        if not uuid2_str:
+            log.warn('%s/uuid/ is missing. recreate is confused, '
+                     'trying our best to recover' % vmpath)
+            needs_reinitialising = True
+            raise XendError('reinit')
+        
+        uuid2 = uuid.fromString(uuid2_str)
+        if uuid1 != uuid2:
+            log.warn('UUID in /vm does not match the UUID in /dom/%d.'
+                     'Trying out best to recover' % domid)
+            needs_reinitialising = True
+    except XendError:
+        pass # our best shot at 'goto' in python :)
 
     vm = XendDomainInfo(xeninfo, domid, dompath, augment = True, priv = priv)
     
@@ -537,7 +538,10 @@ class XendDomainInfo:
             self.getDeviceController(devclass).waitForDevices()
 
     def destroyDevice(self, deviceClass, devid):
-        if type(devid) is str:
+        try:
+            devid = int(devid)
+        except ValueError:
+            # devid is not a number, let's search for it in xenstore.
             devicePath = '%s/device/%s' % (self.dompath, deviceClass)
             for entry in xstransact.List(devicePath):
                 backend = xstransact.Read('%s/%s' % (devicePath, entry),
@@ -547,6 +551,7 @@ class XendDomainInfo:
                     # We found the integer matching our devid, use it instead
                     devid = entry
                     break
+                
         return self.getDeviceController(deviceClass).destroyDevice(devid)